//
//  UIImage+Circle.m
//  BuDeJie
//
//  Created by 梁梓烽 on 16/4/6.
//  Copyright © 2016年 liangzifeng. All rights reserved.
//

#import "UIImage+Circle.h"


@implementation UIImage (Circle)
// 生成一个圆角图片
- (UIImage *)circleImage
{
    // 裁剪图片: 图形上下文
    // 1.开启图形上下文
    // scale:比例因素 点:像素比例 0:自动识别比例因素
    UIGraphicsBeginImageContextWithOptions(self.size, NO, 0);
    // 2.描述圆形裁剪路径
    UIBezierPath *clipPath = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, self.size.width, self.size.height)];
    // 3.设置为裁剪区域
    [clipPath addClip];
    // 4.画图片
    [self drawAtPoint:CGPointZero];
    // 5.取出图片
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    // 6.关闭上下文
    UIGraphicsEndImageContext();
    
    return image;
}

//根据图片名字返回一张圆形图片
+(UIImage *)lzf_circleImageNamed:(NSString *)name
{
    return  [[UIImage imageNamed:name]circleImage];
}
@end
